<template>
  <div class="container">
    <div class="reportform">
      <form @submit="bindFormSubmit">
        <textarea class="reportform_textarea" placeholder="填写报表" name="textarea" focus="true" v-model="textarea" :disabled="shenhe" maxlength="-1"/>
        <button form-type="submit" class="submit" :disabled="shenhe">提交</button>
  </form>
    </div>
  </div>
</template>

<script>
import wx from 'wx'
import api from '@/utils/api'
import Toast from '@/utils/toast'
export default {
  data () {
    return {
      textarea: '',
      shenhe: false
    }
  },

  components: {
  },
  onLoad () {
    let userId = wx.getStorageSync('userInfo').user_id
    console.log(userId)
    this.getwork()
  },
  methods: {
    async bindFormSubmit (e) {
      if (!this.textarea) {
        Toast('请填写报表！');
        return;
      }
      let userId = wx.getStorageSync('userInfo').user_id;
      const res = await api.getreportform({ user_id: userId, reportforms: this.textarea });
      if (res.code === '100') {
        Toast(res.msg, 'success')
      } else {
        Toast(res.msg, 'noicon')
      }
    },
    async getwork () {
      let userId = wx.getStorageSync('userInfo').user_id
      const res = await api.getuserwork({ user_id: userId });
      if (res) {
        if (res.code === '100') {
          this.textarea = res.data.reportforms;
          if (res.data.shenhe === 1) {
            this.shenhe = true
          }
        } else {
        }
      } else {
      }
    }
  },
  created () {
  },
  onShow () {
  },
  onReady () {
  }
}
</script>

<style scoped>
.container {
  height: 100%;
}
.reportform {
  width: 100%;
  padding: 20rpx;
}
.reportform_textarea {
  display: block;
  width: 100%;
  height: 600rpx;
  border: 2rpx solid rgba(151, 151, 151, 0.4);
  box-sizing: border-box;
  padding: 20rpx;
  font-size: 28rpx;
  color: #333;
  margin-bottom: 20rpx;
}
.submit {
  width: 600rpx;
  background: #ff4444;
  color: #fff;
}
</style>
